<?php
if (!defined('__BACKEND__')) die ("you cannot directly access this page");
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
 

_showMenuHeader();
function change_profile(){
    global $db,$user_id,$login_status,$user_edit;
    if ($login_status){
        $sql="select * from app_users where id=$user_id";
        $row=$db->fetch_row($sql);
        extract($row);
        if (empty($user_edit)){
            $user_edit=$user_id;
        }
        $select_social_media=  select_login_type("social_media_type", $social_media_type);
        echo "
<div id=\"table_data\">
<h2>Change Profile</h2>
<form action=\"?mod=users\" method=\"post\">
         <input type=\"hidden\" name=\"action\" value=\"change_profile\" />
          <table>
<tr><td>ID</td><td><input type=\"hidden\" name=\"id\" value=\"$user_id\"/>$user_id 
        <input type=\"hidden\" name=\"user_edit\" value=\"$user_edit\"/></td></tr>
<tr><td>User Name</td><td><b>$user_name</b> </td></tr>
<tr><td>Fullname</td><td><input type=\"text\" name=\"full_name\" class=\"textbox\" value=\"$full_name\"/> </td></tr>
<tr><td valign=top>Short Profile</td><td><textarea cols=45 rows=5 name=\"short_profile\" class=\"textbox\">$short_profile</textarea> </td></tr>
<tr><td>Email</td><td><input type=\"text\" name=\"email\" class=\"textbox\" value=\"$email\" size=45/> </td></tr>
<tr><td>Mobile</td><td><input type=\"text\" name=\"mobile\" class=\"textbox\" value=\"$mobile\"/> </td></tr>
<tr><td>Social Media Login</td><td><input type=\"text\" name=\"social_media_login\" class=\"textbox\" value=\"$social_media_login\"/> </td></tr>
<tr><td>Social Media Type</td><td>
$select_social_media 
    </td></tr>
<tr><td></td><td><input class=button type=\"submit\" value=\"Change My Profile\"/>
        <input class=button type=\"button\" name=\"cancel\" 
        value=\"Cancel\" onclick=\"javascript:history.go(-1);\"/></tr></table>  
   </form></div>";
    }
}
function change_pass_form(){
    echo "<form action=\"?mod=users\" method=\"post\">
        <input type=\"hidden\" name=\"action\" value=\"change_password\" />
        <h2>Change Password</h2>
        <table>
        <tr><td>Current Password</td>
        <td><input type=\"password\" name=\"current\" size=\"20\"/></td></tr>
        <tr><td>New Password</td>
        <td><input id=\"pass_word\" type=\"password\" name=\"newpass\" size=\"20\"/></td></tr>
        <tr><td>Verify Password</td>
        <td><input id=\"verify\" type=\"password\" name=\"verpass\" size=\"20\"/>
        <img src=\"images/spacer.gif\" id=\"msg_pass\" height=\"20\" width=\"20\"/></td></tr>
        <tr><td>&nbsp;</td><td><input type=\"submit\" value=\"Change Password\"/></td></tr>
        </table>
    </form>";
}
function change_password(){
    global $db,$current,$user_id,$newpass,$verpass,$login_status;
    $sql="select * from app_users where id=$user_id";
    $row=$db->fetch_row($sql);
    if (!empty ($row)) extract ($row);
    if (strcmp($current, $pass_word)==0){
        if (strcmp($newpass,$verpass)==0){
            $update="update app_users set pass_word=md5('$newpass') where id=$user_id";
            $db->query($update);
            refresh_to("?mod=panel", "Kembali ke panel User", 2);
        }
    }
}
function profile_process(){
    global $db,$login_status,$user_id,$full_name,$is_admin,
            $short_profile,$social_media_login,$social_media_type,$mobile,$email,$user_edit;
    if ($login_status){
        if ($is_admin=='0'){
        $sql="update app_users set full_name='$full_name',short_profile='$short_profile',
          mobile='$mobile',social_media_login='$social_media_login',
              social_media_type='$social_media_type',email='$email'
          where id=$user_id";
        } else {
          $sql="update app_users set full_name='$full_name',short_profile='$short_profile',
          mobile='$mobile',social_media_login='$social_media_login',
              social_media_type='$social_media_type',email='$email'
          where id=$user_edit";
        }
    $db->query($sql);
    refresh_to("?mod=content", "Kembali ke panel User", 2);
    }
}
switch ($action){
    case 'change_profile':
        profile_process();
        break;
    case 'chprofile':
        change_profile();
        break;
    case 'chpass':
        change_pass_form();
        break;
    case 'change_password':
        change_password();
        break;
    default:
        echo "";
}
?>
<script>
    $("#verify").keyup(
    function (){
        var value2=$(this).val();
        var value1=$("#pass_word").val();
        if (value1!=value2){
            $("#msg_pass").attr('src','images/not_ok.png');
        } else {
            $("#msg_pass").attr('src','images/ok.png');
        }
    });
</script>